package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.CategoryResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: HF62sky
 * @package: com.sky.controller.admin
 * @className: CategoryController
 * @author: SunGang
 * @description: TODO
 * @date: 2023/12/3 17:42
 * @version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/admin/category")
@Api(tags = "分类控制器")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping("page")
    public Result<CategoryResult> findByPage(CategoryPageQueryDTO categoryPageQueryDTO){
     CategoryResult category=categoryService.findByPage(categoryPageQueryDTO);
     return  Result.success(category);
    }

    @PostMapping
    public Result<?> addCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result<?> modifyStatus(@PathVariable Integer status,Long id){
       categoryService.modifyStatus(status,id);
       return  Result.success();
    }

    @GetMapping("/list")
    public Result<List<Category>> findByType(Integer type){
       List<Category> category= categoryService.findByType(type);
       return Result.success(category);
    }


    @PutMapping
    public Result<Category> modifyCategoryById(@RequestBody CategoryDTO categoryDTO){
      categoryService.modifyCategoryById(categoryDTO);
      return Result.success();
    }

    @DeleteMapping
    public Result<?> deleteById(Long id){
        categoryService.deleteById(id);
        return  Result.success();
    }
}
